package com.cskt.petproject178.pojo.vo;

import org.springframework.util.ObjectUtils;

/**
 * 统一响应结果实体类
 *
 * @author admin
 **/

public class ResultVO<T> {
    
    private String code;
    private String msg;
    private T data;


    /**
     * 正常，带返回参数，data:属性包含数据
     * @return
     * @param <T>
     */
    public static <T> ResultVO<T> OK(T data){
        ResultVO<T> resultVO = new ResultVO<>(ResultStatusEnum.SUCCESS);
        resultVO.setData(data);
        return resultVO;
    }

    /**
     * 正常，不带数据
     * @return
     */
    public static ResultVO<Void> OK() {
        return new ResultVO<>(ResultStatusEnum.SUCCESS);
    }

    /**
     * 默认的异常
     * @return
     */
    public static ResultVO<Void> ERR() {
        return ERR(ResultStatusEnum.FAIL);
    }




public static ResultVO<Void> ERR(String code,String msg){
    return new ResultVO<>(code,msg);
}
    /**
     * 非正常情况，异常情况，有很大的灵活，不同的开发人员，导致响应的结果不统一；前端在判断时，就会有问题；
     * 建议将 Code 与 Msg 绑定成对出现 枚举
     * @param statusEnum 状态码枚举 
     */
    public static ResultVO<Void> ERR(ResultStatusEnum statusEnum) {
        return new ResultVO<>(statusEnum.getCode(), statusEnum.getMsg());
    }

    public static ResultVO<Void> ERR(StatusEnum statusEnum) {
        return new ResultVO<>(statusEnum.getCode(), statusEnum.getMsg());
    }


    private ResultVO(ResultStatusEnum statusEnum) {
        this.code = statusEnum.getCode();
        this.msg = statusEnum.getMsg();
    }


    private ResultVO(StatusEnum statusEnum) {
        this.code = statusEnum.getCode();
        this.msg = statusEnum.getMsg();
    }

    private ResultVO(String code, String msg
    ) {
        this.code = code;
        this.msg = msg;
    }
    

    private ResultVO(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
